package cn.lan.generator.utils;

import cn.lan.generator.bean.ProjInfo;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 读取资源配置文件
 */
public class ConfigUtil extends Properties{

	private static final long serialVersionUID = 1L;
	
	private static ConfigUtil instance = null;
	
	public synchronized static ConfigUtil getInstance() {
		if (instance != null) {
			return instance;
		} else {
			instance = new ConfigUtil();
			return instance;
		}
	}

	public ConfigUtil() {
        try {
            InputStream is = ConfigUtil.class.getResourceAsStream("/"+ Constant.CONFIG_PATH);
            this.load(is);
        } catch (IOException e) {
            e.printStackTrace();
        }
	}
	
    public static String getConfigValue(String configKey) {
        return ConfigUtil.getInstance().getProperty(configKey, "utf-8");
    }

	public static String getServerBasePackage(String basePackage) {
		return basePackage+"."+ConfigUtil.getConfigValue(Constant.KEY_SERVER_BASE_PATH);
	}

	public static String getControllerPackage(String basePackage) {
		return basePackage+"."+ConfigUtil.getConfigValue(Constant.KEY_CONTROLLER_PATH);
	}

	public static String getViewControllerPackage(String basePackage) {
		return basePackage+"."+ConfigUtil.getConfigValue(Constant.KEY_VIEW_CONTROLLER_PATH);
	}

	public static String getServerConfigPackage(String basePackage) {
		return basePackage+"."+ConfigUtil.getConfigValue(Constant.SERVER_CONFIG_PATH);
	}

	public static String getAspectPackage(String basePackage) {
		return basePackage+"."+ConfigUtil.getConfigValue(Constant.ASPECT_PATH);
	}

	public static String getFilterPackage(String basePackage) {
		return basePackage+"."+ConfigUtil.getConfigValue(Constant.KEY_FILTER_PATH);
	}

	public static String getInterceptorPackage(String basePackage) {
		return basePackage+"."+ConfigUtil.getConfigValue(Constant.KEY_INTERCEPTOR_PATH);
	}

	public static String getEntityPackage(ProjInfo projInfo) {
		return projInfo.getPackageName()+"."+projInfo.getModuleName()+"."+ConfigUtil.getConfigValue(Constant.KEY_ENTITY_PATH);
	}

	public static String getDtoPackage(ProjInfo projInfo) {
		return projInfo.getPackageName()+"."+projInfo.getModuleName()+"."+ConfigUtil.getConfigValue(Constant.KEY_DTO_PATH);
	}

	public static String getListDtoPackage(ProjInfo projInfo) {
		return projInfo.getPackageName()+"."+projInfo.getModuleName()+"."+ConfigUtil.getConfigValue(Constant.KEY_LIST_DTO_PATH);
	}

	public static String getVoPackage(ProjInfo projInfo) {
		return projInfo.getPackageName()+"."+projInfo.getModuleName()+"."+ConfigUtil.getConfigValue(Constant.KEY_VO_PATH);
	}

	public static String getServicePackage(ProjInfo projInfo) {
		return projInfo.getPackageName()+"."+projInfo.getModuleName()+"."+ConfigUtil.getConfigValue(Constant.KEY_SERVICE_PATH);
	}

	public static String getModulePackage(ProjInfo projInfo) {
		return projInfo.getPackageName()+"."+projInfo.getModuleName();
	}

	public static String getServiceImplPackage(ProjInfo projInfo) {
		return projInfo.getPackageName()+"."+projInfo.getModuleName()+"."+ConfigUtil.getConfigValue(Constant.KEY_SERVICE_IMPL_PATH);
	}

	public static String getMapperPackage(ProjInfo projInfo) {
		return projInfo.getPackageName()+"."+projInfo.getModuleName()+"."+ConfigUtil.getConfigValue(Constant.KEY_MAPPER_PATH);
	}

	public static String getMappingsPackage(ProjInfo projInfo) {
		return projInfo.getPackageName()+"."+projInfo.getModuleName()+"."+ConfigUtil.getConfigValue(Constant.KEY_MAPPINGS_PATH);
	}

	public static String getCommonBeanPackage(String basePackage) {
		return basePackage+"."+ConfigUtil.getConfigValue(Constant.KEY_COMMON_BEAN_PATH);
	}

	public static String getCommonBeanDtoPackage(String basePackage) {
		return basePackage+"."+ConfigUtil.getConfigValue(Constant.KEY_COMMON_BEAN_DTO_PATH);
	}

	public static String getMybatisPlusPackage(String basePackage) {
		return basePackage+"."+ConfigUtil.getConfigValue(Constant.KEY_MYBATIS_PLUS_PATH);
	}

	public static String getCommonBeanVoPackage(String basePackage) {
		return basePackage+"."+ConfigUtil.getConfigValue(Constant.KEY_COMMON_BEAN_VO_PATH);
	}

	public static String getCommonPackage(String basePackage) {
		return basePackage+"."+ConfigUtil.getConfigValue(Constant.KEY_COMMON_PATH);
	}

	public static String getCommonUtilsPackage(String basePackage) {
		return basePackage+"."+ConfigUtil.getConfigValue(Constant.KEY_UTIL_PATH);
	}

	public static String getCommonConfigPackage(String basePackage) {
		return basePackage+"."+ConfigUtil.getConfigValue(Constant.KEY_COMMON_CONFIG_PATH);
	}

	public static String getExceptionPackage(String basePackage) {
		return basePackage+"."+ConfigUtil.getConfigValue(Constant.KEY_EXCEPTION_PATH);
	}

	public static String getValidatePackage(String basePackage) {
		return basePackage+"."+ConfigUtil.getConfigValue(Constant.KEY_VALIDATE_PATH);
	}

	public static String getRedisPackage(String basePackage) {
		return basePackage+"."+ConfigUtil.getConfigValue(Constant.KEY_REDIS_PATH);
	}

	public static String getCommonTokenPackage(String basePackage) {
		return basePackage+"."+ConfigUtil.getConfigValue(Constant.KEY_COMMON_TOKEN_PATH);
	}

	public static String getCommonTokenBeanPackage(String basePackage) {
		return basePackage+"."+ConfigUtil.getConfigValue(Constant.KEY_COMMON_TOKEN_BEAN_PATH);
	}

	public static String getCommonTokenConfigPackage(String basePackage) {
		return basePackage+"."+ConfigUtil.getConfigValue(Constant.KEY_COMMON_TOKEN_CONFIG_PATH);
	}

	public static String getTokenManagerPackage(String basePackage) {
		return basePackage+"."+ConfigUtil.getConfigValue(Constant.KEY_COMMON_TOKEN_MANAGER_PATH);
	}

	public static String getEnumsPackage(String basePackage) {
		return basePackage+"."+ConfigUtil.getConfigValue(Constant.KEY_ENUM_PATH);
	}

	public static String getAnnotationPackage(String basePackage) {
		return basePackage+"."+ConfigUtil.getConfigValue(Constant.KEY_ANNOTATION_PATH);
	}
}
